package com.tian.view.draw.advance

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment

/**
 * @author tiansongtao
 * @date 2023/1/4 14:12
 *
 * 绘图的进阶
 * 1：Pierre Bezier 贝塞尔曲线，这种曲线很顺滑
 */
class DrawAdvanceFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        (requireActivity() as AppCompatActivity).supportActionBar?.title = "绘图进阶"
        val root = LinearLayout(requireContext())
        root.orientation = LinearLayout.VERTICAL
        val lp = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        root.layoutParams = lp
        root.addView(PierreBezierPathView(requireContext()).apply { layoutParams = getChildViewLayoutParams() })
        root.addView(ShadowLayerView(requireContext()).apply { layoutParams = getChildViewLayoutParams() })
        root.addView(MaskFilterView(requireContext()).apply { layoutParams = getChildViewLayoutParams() })
        return root
    }

    private fun getChildViewLayoutParams() = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0)
        .apply { weight = 1f }


}